	package actions;

	import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
	import javax.servlet.http.HttpServletResponse;

	import org.apache.struts.action.*;
	
	//import db.DbException;
	import forms.RegisterSubmitForm;
import model.Applicant;
import model.Database;

public class RegisterSubmitAction extends Action{
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){

		// Cast the form
		RegisterSubmitForm iForm = (RegisterSubmitForm) form;
		Applicant applicant = new Applicant();
		
		// set applicant in user database (DATABASE CALL) TODO
		request.setAttribute("Applicant", applicant);
		
		try {
			Database.createAccount(iForm.getUsername(), iForm.getPassword(), iForm.getEmail());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		//submit to db
		if(false ) {
			return mapping.findForward("failure");
		}
		
		return mapping.findForward("success");
	}
	

}
